//
//  HFTopView.m
//  LetsParty
//
//  Created by rimi on 15/9/10.
//  Copyright (c) 2015年 MLin. All rights reserved.
//

#import "HFTopView.h"
#import "NSString+Extension.h"
#import "CYYNetWorkManager+PartyDetail.h"
@interface HFTopView ()
@property (copy, nonatomic) NSString* secretString;
@property (strong, nonatomic) NSString *titleLabelString;
- (void)initizlizeUserInterface;
@end
@implementation HFTopView

- (instancetype)initWith:(NSDictionary *)stringArray;
{
    self = [super init];
    if (self) {
    
        NSString *addressarray = [stringArray objectForKey:@"address"];
        _addressString = addressarray;
//                NSLog(@"pppppppp%@", _addressString);
     
        id obj = [stringArray objectForKey:@"detial"];
        if ([obj isKindOfClass:[NSArray class]]) {
//            NSLog(@"is array");
        }
        else if([obj isKindOfClass:[NSString class]]){
//            NSLog(@"is string");
        }
        NSString *detialArray = [stringArray objectForKey:@"detial"];
       
        _detialString = detialArray;
        NSString *peopleArray = [stringArray objectForKey:@"people"];
         _peopleStringj = peopleArray;
        //题目
        NSString *titleArray = [stringArray objectForKey:@"partyTitle"];
        _titleLabelString = titleArray;
        
        _secretString = [stringArray objectForKey:@"SecretCode"];
        
        
        if (stringArray) {
             [self initizlizeUserInterface];
        }
        
        
    }
    return self;
}
#pragma mark - init
- (void)initizlizeUserInterface
{
    
    //
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1) adjustWidth:YES];
//    view.backgroundColor = [UIColor grayColor];
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 0.5 ) adjustWidth:YES];
    view1.backgroundColor = [UIColor grayColor];
    
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 0.5 ) adjustWidth:YES];
    view2.backgroundColor = [UIColor grayColor];
    
    UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 0.5 ) adjustWidth:YES];
    view3.backgroundColor = [UIColor grayColor];
    
    
    //
    
    _titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60 + self.titleLabel.frame.size.height) adjustWidth:NO];

    //label
        [_titleView addSubview:self.titleLabel];
    
    _titleJoinLabel = ({
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10 + self.titleLabel.frame.size.height, 50, 20) adjustWidth:YES];
        label.font = STATUS_FONT;
        [_titleView addSubview:label];
       
        label.textAlignment = NSTextAlignmentCenter;
   
        label;
    
    });
    [_titleView addSubview:self.titleJoinLabel];
    //
//    [_titleView addSubview:view];
    
    //
    
    
    
    UILabel *basicInfoLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.titleView.frame.size.height - 20*DHFlexibleHorizontalMutiplier(), 100*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
    basicInfoLabel.font = [UIFont systemFontOfSize:14];
    basicInfoLabel.text = @"基本信息";
    basicInfoLabel.font = [UIFont boldSystemFontOfSize:17 * DHFlexibleHorizontalMutiplier()];
    [_titleView addSubview:basicInfoLabel];
    
    
    // 上面
    self.titleView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.titleView];
    
    


    
    UILabel *time = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 70, 20) adjustWidth:YES];
    time.font = [UIFont systemFontOfSize:17 * DHFlexibleHorizontalMutiplier()];
    time.text = @"时间：";
    
    UILabel *secret = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 70, 20) adjustWidth:YES];
    secret.font = [UIFont systemFontOfSize:17 * DHFlexibleHorizontalMutiplier()];
    secret.text = @"暗号：";
    
    
    UILabel *address = [[UILabel alloc] initWithFrame:CGRectMake(10, 70, 70, 20) adjustWidth:YES];
    address.text = @"地址：";
    address.font = [UIFont systemFontOfSize:17 * DHFlexibleHorizontalMutiplier()];
    
    

    
    UILabel *originator = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 90, 20) adjustWidth:YES];
    originator.text = @"发起人：";
    originator.font = [UIFont systemFontOfSize:17 * DHFlexibleHorizontalMutiplier()];
    
    

    UIView *backgrondView = [[UIView alloc] initWithFrame:CGRectMake(0, self.titleView.frame.size.height, 320 *DHFlexibleHorizontalMutiplier(), 55 *DHFlexibleHorizontalMutiplier() + self.addressLabel.frame.size.height + 40 *DHFlexibleHorizontalMutiplier())];
    _basicInfoView = backgrondView;
    [self addSubview:backgrondView];
    backgrondView.backgroundColor = [UIColor whiteColor];
    
    UILabel *detialLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.basicInfoView.frame.size.height - 20, 60, 20)];
    detialLabel.text = @"详情";
    detialLabel.font = [UIFont boldSystemFontOfSize:17 * DHFlexibleHorizontalMutiplier()];
    [_basicInfoView addSubview:time];
    [_basicInfoView addSubview:address];
    [_basicInfoView addSubview:secret];
    [_basicInfoView addSubview:originator];
    [_basicInfoView addSubview:detialLabel];
    [_basicInfoView addSubview:self.addressLabel];
    [_basicInfoView addSubview:self.secretLabel];
    [_basicInfoView addSubview:self.addressButton];
    [_basicInfoView addSubview:self.timeLabel];
    [_basicInfoView addSubview:self.originatorLabel];
    self.basicInfoView.backgroundColor = [UIColor whiteColor];
//    NSLog(@"basic:%@", self.basicInfoView);
    //
    [self.basicInfoView addSubview:view1];
    //
    
    //介绍
    UILabel *numberslabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20*DHFlexibleHorizontalMutiplier() + self.titleDetialLabel.frame.size.height, 120*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
    numberslabel.text = @"参加人员";
    numberslabel.font = [UIFont boldSystemFontOfSize:17 * DHFlexibleHorizontalMutiplier()];
    [self addSubview:self.intrBackView];
    [self.intrBackView addSubview:self.titleDetialLabel];
    [self.intrBackView addSubview:self.peoplesButton];
    [self.intrBackView addSubview:numberslabel];
//    [self.intrBackView addSubview:self.numberLabel];

//     NSLog(@"intrBackView:%@", self.intrBackView);
    self.intrBackView.backgroundColor = [UIColor whiteColor];
    //
    [self.intrBackView addSubview:view2];
    //
    [self.peopleView addSubview:self.peopleLabel];
    [self.peopleView addSubview:self.massageBoard];
    [self.peopleView addSubview:self.massageBoardButton];
    [self addSubview:self.peopleView];
    //
    [self.peopleView addSubview:view3];
    
    //
//    self.frame = DHFlexibleFrame(CGRectMake(0, 0, 320, self.intrBackView.frame.origin.y + self.intrBackView.frame.size.height), NO);
    
    self.frame = CGRectMake(0, 0, 320 * DHFlexibleHorizontalMutiplier(), self.peopleView.frame.origin.y + self.peopleView.frame.size.height);
    self.backgroundColor = [UIColor grayColor];
    self.titleJoinLabel.textColor = [UIColor whiteColor];
}
#pragma mark - getter
- (UILabel *)secretLabel
{
    if (!_secretLabel) {
        _secretLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60, 30, 200, 20) adjustWidth:YES];
            label.backgroundColor= [UIColor clearColor];
            label.text = _secretString;
            label;

        
        });
        
    }
    return _secretLabel;


}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        
        _titleLabel = ({
            
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10*DHFlexibleVerticalMutiplier(), 5*DHFlexibleVerticalMutiplier(),250*DHFlexibleVerticalMutiplier(), 0)];
            label.numberOfLines = 0;
            label.text = _titleLabelString;
            label.font = [UIFont boldSystemFontOfSize:20 * DHFlexibleHorizontalMutiplier()];
            [label sizeToFit];
            
            label;

        
        });
        
        
    }
    return _titleLabel;


}


- (UIButton *)massageBoardButton
{
    if (!_massageBoardButton) {
        
        _massageBoardButton = ({
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(270 *DHFlexibleHorizontalMutiplier(), self.massageBoard.frame.origin.y, 20 *DHFlexibleHorizontalMutiplier(), self.massageBoard.frame.size.height);
            [button setImage:[UIImage imageNamed:@"iconfont-jiantouyou"] forState:UIControlStateNormal];

            button;
        });
        
    }
    return _massageBoardButton;


}
- (UIButton *)peoplesButton
{
    if (!_peoplesButton) {
        _peoplesButton = ({
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(270*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier() + self.titleDetialLabel.frame.size.height, 20 * DHFlexibleHorizontalMutiplier(), self.numberLabel.frame.size.height);
            [button setImage:[UIImage imageNamed:@"iconfont-jiantouyou"] forState:UIControlStateNormal];
            button;
        });
    }
    return _peoplesButton;


}

- (UIButton *)addressButton
{
    if (!_addressButton) {
        _addressButton = ({
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = self.addressLabel.frame;
//            button.backgroundColor = [UIColor greenColor];
            button;
        });
    }
    return _addressButton;

}
- (UILabel *)massageBoard
{
    if (!_massageBoard) {
        _massageBoard = ({
             UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, self.peopleLabel.frame.size.height + 20*DHFlexibleHorizontalMutiplier(), 60 * DHFlexibleHorizontalMutiplier(), 20 * DHFlexibleHorizontalMutiplier())];
            label.text = @"留言板";
            label.font = [UIFont boldSystemFontOfSize:17 * DHFlexibleHorizontalMutiplier()];
            label.backgroundColor= [UIColor whiteColor];
            label;

        });
    }
    return _massageBoard;

}
- (UILabel *)peopleLabel
{
    if (!_peopleLabel) {
//        _peopleStringj = @"啊；韩国；啊哈格拉大好时光拉黑给拉黑了嘎哈绿化管理卡和管理卡好了公开哈老公哈理工还拉黑过来看这个会卡怪好了卡";
//        CGSize detialStringSize = [self.peopleStringj sizeWithFont:[UIFont systemFontOfSize:14 * DHFlexibleHorizontalMutiplier()] maxSize:DHFlexibleSize(CGSizeMake(250, 1000), YES)];
//        _peopleStringj = [NSString stringWithFormat:@"%@", _peopleStringj];
//        NSLog(@"%@", _peopleStringj);
        _peopleLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10,250, 0) adjustWidth:YES];
            label.numberOfLines = 0;
            _peopleStringj = [NSString stringWithFormat:@"%@", _peopleStringj];
            label.text = _peopleStringj;
            label.font = [UIFont systemFontOfSize:14 * DHFlexibleHorizontalMutiplier()];
            [label sizeToFit];
            
            label;

        
        });

        
    }
    return _peopleLabel;


}
- (UIView *)peopleView
{
    if (!_peopleView) {
        _peopleView = ({
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, self.intrBackView.frame.size.height + self.intrBackView.frame.origin.y, 320 * DHFlexibleHorizontalMutiplier(), self.massageBoard.frame.size.height + self.massageBoard.frame.origin.y)];
            view.backgroundColor = [UIColor whiteColor];
            view;
        
        });
    }
    return _peopleView;

}
- (UILabel *)numberLabel
{
    if (!_numberLabel) {
        _numberLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(110, 20 + self.titleDetialLabel.frame.size.height, 30, 20) adjustWidth:YES];
            label.backgroundColor= [UIColor clearColor];
            label.font = [UIFont boldSystemFontOfSize:14 * DHFlexibleHorizontalMutiplier()];
//            label.text =@"2";
            label;
            
 
        
        });
    }
    return _numberLabel;


}
- (UIView *)intrBackView
{
    if (!_intrBackView) {
//        _intrBackView = [[UIView alloc] initWithFrame:CGRectMake(0,10 + self.basicInfoView.frame.origin.y + self.basicInfoView.frame.size.height, 320, self.titleDetialLabel.frame.size.height + self.numberLabel.frame.size.height + 20) adjustWidth:NO];
         _intrBackView = [[UIView alloc] initWithFrame:CGRectMake(0, self.basicInfoView.frame.origin.y + self.basicInfoView.frame.size.height, 320 * DHFlexibleHorizontalMutiplier(), (self.numberLabel.frame.size.height + 20*DHFlexibleHorizontalMutiplier() + self.titleDetialLabel.frame.size.height) )];
        _intrBackView.backgroundColor = [UIColor whiteColor];
        
    }
    return _intrBackView;


}
- (UILabel *)titleDetialLabel
{
    if (!_titleDetialLabel) {
        _detialString = [NSString stringWithFormat:@"%@", _detialString];
//        CGSize detialStringSize = [_detialString sizeWithFont:[UIFont systemFontOfSize:16] maxSize:DHFlexibleSize(CGSizeMake(250, HUGE_VAL), YES)];
        
        _titleDetialLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 250 * DHFlexibleHorizontalMutiplier(), 0)];
            label.numberOfLines = 0;
            label.text = _detialString;

            [label sizeToFit];
            label;
        });
        
    }
    return _titleDetialLabel;


}
- (UILabel *)timeLabel
{
    if (!_timeLabel) {
        _timeLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60, 50, 250, 20) adjustWidth:YES];
            label.backgroundColor= [UIColor clearColor];
            label;
        });
    }
    return _timeLabel;
    
}
- (UILabel *)addressLabel
{
  
    if (self.addressString) {
//        NSLog(@"%@", self.addressString);
    
    if (!_addressLabel) {

        _addressString = [NSString stringWithFormat:@"%@", _addressString];
        CGSize addressStringSize = [_addressString sizeWithFont:[UIFont systemFontOfSize:16] maxSize:DHFlexibleSize(CGSizeMake(200, HUGE_VAL), YES)];
        _addressLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60, 70, addressStringSize.width, addressStringSize.height) adjustWidth:YES];
//            label.text = _addressString;
            label.font = [UIFont systemFontOfSize:16];
            label.numberOfLines = 0;
            label;
        });
        
    }
    }
    return _addressLabel;
    
}
- (UILabel *)originatorLabel
{
    if (!_originatorLabel) {
        _originatorLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(70, 10, 200, 20) adjustWidth:YES];
            label.backgroundColor = [UIColor clearColor];
            label;
        });
    }
    return _originatorLabel;
    
    
}

@end
